public class ThreadDemo2 {
    public static void main(String[] args) {
        MyBlockingQueue queue = new MyBlockingQueue();
        //消费者
        Thread t1 = new Thread(() -> {
            while(true){
                try {
                    int value = queue.take();
                    System.out.println("消费者: " + value);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        //生产者：
        Thread t2 = new Thread(() -> {
            int value = 0;
            while(true){
                try {
                    System.out.println("生产："+ value);
                    queue.put(value);
                    Thread.sleep(20);
                    value++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();
    }
}
